package com.carkeeper.servetype.controller;


import com.carkeeper.entity.Result;
import com.carkeeper.pojo.KnowledgeBaseInfo;
import com.carkeeper.servetype.service.KnowledgeService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(value = "知识库管理")
@RestController
@RequestMapping("/knowledge")
public class KnowledgeController {



    @Autowired
    private KnowledgeService knowledgeService;


    /**
     * 展示知识库列表
     * @param map
     * @return
     */
    @GetMapping("/showAllKnowledge/{currentPage}/{pageSize}")
    public Result<List<KnowledgeBaseInfo>> showAllKnowledge(@RequestParam Map<String, String> map,@PathVariable("currentPage") String currentPage,@PathVariable("pageSize") String pageSize) {
        return knowledgeService.showAllKnowledge(map,currentPage,pageSize);
    }


    /**
     * 查询全部分类
     * @return
     */
    @GetMapping("/showCategory")
    public Result<Map<String, List<String>>> findCategory(@RequestParam Map map) {
        return knowledgeService.findCategory(map);
    }


    /**
     * 添加推文
     * @param knowledgeBaseInfo
     * @return
     */
    @PostMapping("/add")
    public Result addKnowledgeBaseInfo(@RequestBody KnowledgeBaseInfo knowledgeBaseInfo){
        return knowledgeService.addKnowledgeBaseInfo(knowledgeBaseInfo);
    }


    /**
     * 更新推文
     * @param knowledgeBaseInfo
     * @return
     */
    @PutMapping("/update")
    public Result update( @RequestBody KnowledgeBaseInfo knowledgeBaseInfo) {
        return knowledgeService.update(knowledgeBaseInfo);
    }


    /**
     * 删除推文
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Long id) {
        return knowledgeService.delete(id);
    }


    /**
     * 根据分类查询知识库
     * @param type
     * @return
     */

    @GetMapping("/findKnowledgeByCategory/{type}")

    public Result<List<KnowledgeBaseInfo>> findKnowledgeByCategory(@PathVariable("type") String type) {
        return knowledgeService.findKnowledgeByCategory(type);
    }





}
